package control;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.PriorityDTO;
import business.PriorityManager;

/**
 * Servlet implementation class DeletePriorityServlet
 */
@WebServlet("/DeletePriority")
public class DeletePriorityServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}
	
	
	private void doProcess(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
	int id = Integer.parseInt(request.getParameter("priorityID"));
	PriorityManager um = new PriorityManager();
	PriorityDTO priority = um.findPriority(id);
	um.deletePriority(priority);
	RequestDispatcher rd = request.getRequestDispatcher("/LoadPriority");
	rd.forward(request, response);
	}
}
